package com.dream.cgomallcore.util;

import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.UUID;


public class NumRandom {
    //生成token
    public static String createUUID(){
        return UUID.randomUUID()+"";
    }

    /**
     * 生成随机字符串
     * @param num 生成数量
     * @return 随机数字符串
     */
    public static String getRandomString(Integer num) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < num; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 生成随机数
     * @param num 生成数量
     * @return 随机数字符串
     */
    public static String getRandomNum(Integer num) {
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < num; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
}
